package com.highcom.config;

import com.highcom.bean.Pet;
import com.highcom.bean.User;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.springframework.context.annotation.ImportResource;

//@Configuration(proxyBeanMethods = true)
@Configuration//(proxyBeanMethods = false)
@ImportResource("classpath:bean.xml")
public class MyConfig {

    @Bean("tom")
    public Pet getPet(){
        Pet tom = new Pet();
        tom.setName("tom");
        return tom;
    }

    //当容器中含有tom组件时，user01才生效
    @ConditionalOnBean(name = "tom")//可以根据 @Bean("tom")有无来决定user01是否存在
    @Bean
    public User user01(){
        User zhangsan = new User();
        zhangsan.setName("zhangsan");
        zhangsan.setAge(18);
        zhangsan.setPet(getPet());
        return zhangsan;
    }





}
